#!/usr/bin/perl
#
# Run campus scenario and plot result
#

# run 'campus network under attack'
print STDERR "Running campus under attack scenario...\n";
`java SSF.Net.Net 57600 campusUnderAttack.dml >& campusUnderAttack.out`;

# extract data for plotting
print STDERR "Extracting data...\n";
`cat campusUnderAttack.out | campusDataExtr.pl`;

# generate plot script
my $plotscript = "/tmp/campus.gnuplot"; 
print STDERR "Generating temp gnuplot file $plotscript...\n";
my $grphxfile = "campus";
open(PLSCR, "> $plotscript") or die "Couldn't open temporary gnuplot script file $plotscript\n";
print PLSCR <<__EOP__;
#
# example gnuplot file, shows global worm infection and infections on 
# local network
#

set terminal png color
set output "$grphxfile.png"
#set terminal postscript eps color
#set output "$grphxfile.eps"
set xlabel "time [hours]"
set ylabel "number of infected hosts (globally)"

plot "campus_epidemic_growth.txt" using (\$1/3600):(\$2) title "infected hosts" with lines, "campus_infections.txt" using (\$1/3600):0 title "infections in local network" with points lt 3
__EOP__
close(PLSCR);

# plot result
print STDERR "Plotting result -> $grphxfile.png\n";
`gnuplot /tmp/campus.gnuplot`;

# remove plot script
print STDERR "Deleting temp gnuplot file $plotscript...\n";
`rm $plotscript`;
